<template>
	<view class="home">
		<view class="search">
			<u-search placeholder="请输入..." v-model="searchKeyword" round :clearabled="true" :show-action="false" input-align="center" @search="handleSearch"></u-search>
		</view>
		<view class="tabs">
			<view class="tabs-main">
				<u-tabs :list="listTabs" :current="current" @change="change"></u-tabs>
			</view>
		</view>
		<view>
			<u-waterfall v-model="list" ref="uWaterfall">
				<template v-slot:left="{leftList}" >
					<view class="demo-warter" v-for="(item, index) in leftList" :key="index" @click="goXiang(item.id)">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.imgUrl" :index="index"  style="height: 20vh;"></u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" v-for="(item, index) in rightList" :key="index" @click="goXiang(item.id)">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.imgUrl" :index="index" style="height: 20vh;"></u-lazy-load>
						<view class="demo-title">
							{{item.name}}
						</view>
						<view class="demo-price">
							{{item.price}}元
						</view>
					</view>
				</template>
			</u-waterfall>
		</view>
		<view v-if="list.length == 0">
			<view style="font-size: 30px;text-align: center;margin-top: 50px;">
				暂时没有数据
			</view>
		</view>
	</view>
</template>

<script>
	import { getstoreList,getChangestoreList,poststoreList } from '../../api/store/api';
	export default{
		data(){
			return {
				listTabs:[
					{ name:'全部' },
					{ name: '乐器' },
					{ name: '活动周边' },
					{ name: '音乐学习' }
				],
				current: 0,
				searchKeyword:'',
				loadStatus: 'loadmore',
				flowList: [],
				list: []
			}
		},
		onLoad() {
			this.getStoreListData()
		},
		onReachBottom() {
		},
		methods:{
			change(e){
				this.current = e
				this.clear()
				if(e == 0){
					this.getStoreListData()
				}else{
					getChangestoreList(e).then(res => {
						if(res.code == 200){

							this.list = res.rows
							console.log(this.list)
						}
					})
				}
			},
			getStoreListData(){
				getstoreList().then(res => {
					if(res.code == 200){
						this.list = res.rows
						console.log(this.list)
					}
				})
			},
			// 删除该商品
			remove(id) {
				this.$refs.uWaterfall.remove(id);
			},
			clear() {
				this.$refs.uWaterfall.clear();
			},
			goXiang(id) {
				uni.navigateTo({
				    url: `/pages/store/xiangqing/xiangqing?id=${id}`,
				  });
			}
		}
	}
	
</script>

<style>
	.tabs{
		background-color: #fff;
	    padding: 0 40px;
	}
	.MainConent{
		
	}
	.search{
		padding:0 20px;
	}
	:deep(.u-input){
		font-size: 18px;
	}
	/* page不能写带scope的style标签中，否则无效 */
	page {
		background-color: rgb(240, 240, 240);
	}
	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}
	
	.u-close {
		position: absolute;
		top: 32rpx;
		right: 32rpx;
	}
	
	.demo-image {
		width: 100%;
		border-radius: 4px;
	}
	
	.demo-title {
		font-size: 30rpx;
		margin-top: 5px;
		color: $u-main-color;
	}
	
	.demo-tag {
		display: flex;
		margin-top: 5px;
	}
	
	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}
	
	.demo-tag-text {
		border: 1px solid $u-type-primary;
		color: $u-type-primary;
		margin-left: 10px;
		border-radius: 50rpx;
		line-height: 1;
		padding: 4rpx 14rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
		font-size: 20rpx;
	}
	
	.demo-price {
		font-size: 30rpx;
		margin-top: 5px;
		color: #ff3b5e;
	}
	
	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
	}
</style>